//
//  MPMinePageController.m
//  MarkPlatform
//
//  Created by xiao6 on 2017/12/19.
//  Copyright © 2017年 AT. All rights reserved.
//

#import "MPMinePageController.h"
#import <VTMagic/VTMagic.h>
#import "MPMineTaskController.h"

@interface MPMinePageController ()<VTMagicViewDelegate, VTMagicViewDataSource>

@property (nonatomic, strong) VTMagicController *magicController;
@end

@implementation MPMinePageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showNavTitle:@"我的任务" backItem:YES];
    
    [self addChildViewController:self.magicController];
    [self.magicController didMoveToParentViewController:self];
    [self.view addSubview:self.magicController.view];
    [self.magicController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.magicController.view.superview).insets(UIEdgeInsetsMake(NAVI_HIGHT, 0, 0, 0));
    }];
    [self.magicController.magicView reloadData];
}

#pragma mark - actions


#pragma mark - VTMagicViewDataSource VTMagicViewDelegate
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return @[@"已成功", @"已失败", @"已取消", @"待审核", @"申诉中"];
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifiers";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:[UIColor colorWithRGB:0x666666] forState:UIControlStateNormal];
        [menuItem setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont boldSystemFontOfSize:15.0f];
    }
    return menuItem;
}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    MPMineTaskController *vc = [[MPMineTaskController alloc] init];
    switch (pageIndex) {
        case 0:
            vc.state  = MPMarkStateSuccess;
            break;
        case 1:
            vc.state  = MPMarkStateFail;
            break;
        case 2:
            vc.state  = MPMarkStateCanceled;
            break;
        case 3:
            vc.state  = MPMarkStateReviewing;
            break;
        case 4:
            vc.state  = MPMarkStateAppealing;
            break;
            
        default:
            break;
    }
    
    return vc;
}

#pragma mark - getter
- (VTMagicController *)magicController {
    if (!_magicController) {
        _magicController = [[VTMagicController alloc]init];
        _magicController.magicView.sliderColor = [UIColor appColor];
        _magicController.magicView.navigationColor = [UIColor colorWithRGB:0xF3F3F3];
        _magicController.magicView.scrollEnabled = NO;
        _magicController.magicView.switchStyle = VTSwitchStyleDefault;
        _magicController.magicView.layoutStyle = VTLayoutStyleDivide;
        _magicController.magicView.navigationHeight = 44.0f;
        _magicController.magicView.sliderWidth = 11.0f;
        _magicController.magicView.sliderHeight = 2.0f;
        _magicController.magicView.sliderOffset = -5.0f;
        [_magicController.magicView setSliderView:({
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 11, 2)];
            view.clipsToBounds = YES;
            view.layer.cornerRadius = 1.0f;
            view.backgroundColor = [UIColor appColor];
            view;
        })];
        _magicController.magicView.dataSource = self;
        _magicController.magicView.delegate = self;
        _magicController.magicView.separatorColor = [UIColor clearColor];
    }
    return _magicController;
}

@end
